#ifndef SESSION_H
#define SESSION_H

#include "common.h"
#include "infos.h"
#include <SQLiteCpp/SQLiteCpp.h>
#include <vector>

// 前向声明
class CommandHandler;

class Session
{
private:
    int m_socket;
    int m_isLogin;
    int m_account;
    UserInfo m_userInfo;
    SQLite::Database m_db;

public:
    Session(int socket);
    ~Session();
    
    int GetSocket() { return m_socket; }
    int GetAccount() { return m_account; }
    bool GetIsLogin() { return m_isLogin == 1; }
    UserInfo GetUserInfo() { return m_userInfo; }
    
    void SetAccount(int account) { m_account = account; }
    void SetIsLogin(bool isLogin) { m_isLogin = isLogin ? 1 : -1; }
    void SetUserInfo(UserInfo info) { m_userInfo = info; }
    
    int handleMsg(nlohmann::json msg);
    void sendMsg(nlohmann::json &j);
    void sendMsg(int fd, nlohmann::json &j);
    void sendMsg(std::vector<int> fds, nlohmann::json &j);
    nlohmann::json recvMsg();
    void cleanSession();
    
    std::vector<int> getGroupMember(int groupId);
    std::vector<int> getFriendList(int account);
    std::vector<int> getGroupList(int account);
    std::vector<int> getFriendFd(std::vector<int> accounts);
    int getFriendFd(int account);
    void sendSystemMsg(int fd, std::string msg);
    int getGroupOwnerFd(int groupId);
    
    SQLite::Database& getDatabase() { return m_db; }
};

#endif